package com.my.main.service.sysConfig.serviceImpl;

import com.my.main.base.mapper.BaseMapper;
import com.my.main.base.service.Impl.BaseServiceImpl;
import com.my.main.common.utils.IdWorker;
import com.my.main.entity.sysConfig.SysConfigCode;
import com.my.main.mapper.sysConfig.SysConfigCodeMapper;
import com.my.main.service.sysConfig.SysConfigCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class SysConfigCodeServiceImpl extends BaseServiceImpl<SysConfigCode> implements SysConfigCodeService {

    @Autowired
    private IdWorker idWorker;
    @Autowired
    private SysConfigCodeMapper sysConfigCodeMapper;
    @Resource(name= "sysConfigCodeMapper")
    public void setBaseMapper(BaseMapper<SysConfigCode> sysConfigCodeMapper) {
        super.setBaseMapper(sysConfigCodeMapper);
    }

    @Override
    public void isDeleteByCodeKey(String codeKey) {
        sysConfigCodeMapper.isDeleteByCodeKey(codeKey);
    }

    @Override
    public List<SysConfigCode> queryListByCodeKey(String codeKey) {
        return sysConfigCodeMapper.queryListByCodeKey(codeKey);
    }

    @Override
    public void isSave(List<SysConfigCode> sysConfigCodes) {

        SysConfigCode sysConfigCode;
        for (int i = 0; i < sysConfigCodes.size(); i++) {
            sysConfigCode = new SysConfigCode();
            sysConfigCode.setCodeId(idWorker.nextId() + "");
            sysConfigCode.setCodeKey(sysConfigCodes.get(i).getCodeKey());
            sysConfigCode.setLabel(sysConfigCodes.get(i).getLabel());
            sysConfigCode.setEnumVal(sysConfigCodes.get(i).getEnumVal());
            sysConfigCode.setEnumTxt(sysConfigCodes.get(i).getEnumTxt());
            sysConfigCodeMapper.isSave(sysConfigCode);
        }
    }
}
